﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;


namespace Web.group
{
    public partial class departmentadd : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Hashtable user = PhoneBook.Users.Users.get(Commons.StrUtil.FormatValue(Session["userid"]));

                //分公司
                DataSet ds = PhoneBook.Group.BranchOffice.list(Commons.StrUtil.FormatValue(user["groupid"]));

                Commons.ControlUtil.BindDDL(ddlBo, ds, "boname", "id", "非分公司", "");

                if (user["IsBOOper"] != DBNull.Value && Convert.ToBoolean(user["IsBOOper"]))
                {
                    ddlBo.Enabled = false;

                    ddlBo.SelectedValue = user["bo"].ToString();
                }
            }
        }

        protected void btn_save_Click(object sender, EventArgs e)
        {
            Hashtable user = PhoneBook.Users.Users.get(Commons.StrUtil.FormatValue(Session["userid"]));

            Hashtable department = new Hashtable();
            department["departmentname"] = txb_departmentname.Text;
            department["groupid"] = user["groupid"];
            department["boid"] = ddlBo.SelectedValue;

            PhoneBook.Group.Department.add(department);
            Helper.ShowMessage(u_message, controls.UCMessageType.success, "保存成功");

            AddLog("新添加了部门：{0}", department["departmentname"]);
        }   
    }
}